function MultiTarget()
	if modkeytime == nil then 
		modkeytime = 0 
	end
	if Selector == nil then
		Selector = 0
	end
	
	if IsRightControlKeyDown()   and GetTime() - modkeytime > 0.3  then
		modkeytime = GetTime()
	  	if Selector == 0 then 
	    	Selector = 1 
	    print("Rotation mode: \124cFF3BB0FFArea of Efect")
	    	PQR_SwapRotation("Subtlety_PVP_AoE (Lolomo_SubPVP)")
	  	elseif Selector == 1 then
	    	Selector = 0 
	    	print("Rotation mode: \124cFFD12727Single target")
	    	PQR_SwapRotation("Subtlety_PVP (Lolomo_SubPVP)")
	  	
		
		end
	end
end

-----------------------------------------------------------------------


local slows 			= {
	45524,		-- Chains of Ice
	50435,		-- Chilblains
	115000,		-- Remorseless Winter
	50259,		-- Dazed 
	58180,		-- Infected Wounds
	61391,		-- Typhoon
	127797,		-- Ursol's Vortex
	82941,		-- Ice Trap (Hunter)
	135299,		-- IceTrap Debuff
	35101,		-- Concussive Barrage
	5116,		-- Concussive Shot
	61394,		-- Frozen Wake 
	13810,		-- Ice Trap
	50433,		-- Ankle Crack 
	54644,		-- Frost Breath 
	121288,		-- Chilled 
	120,		-- Cone of Cold
	116,		-- Frostbolt
	44614,		-- Frostfire Bolt
	113092,		-- Frost Bomb
	31589,		-- Slow
	116095,		-- Disable
	118585,		-- Leer of the Ox
	123727,		-- Dizzying Haze
	123586,		-- Flying Serpent Kick
	110300,		-- Burden of Guilt
	63529,		-- Dazed - Avenger's Shield
	20170,		-- Seal of Justice
	15407,		-- Mind Flay
	3409,		-- Crippling Poison
	26679,		-- Deadly Throw
	119696,		-- Debilitation
	3600,		-- Earthbind 
	77478,		-- Earthquake 
	8034,		-- Frostbrand Attack
	8056,		-- Frost Shock
	51490,		-- Thunderstorm
	18223,		-- Curse of Exhaustion
	47960,		-- Shadowflame
	1715,		-- Hamstring
	12323,		-- Piercing Howl
	1604		-- Dazed 

				}		
local immuneToSlow	= {
					-- DEATH KNIGHT
					-- DRUID
					-- HUNTER (Master's Call / Bestial Wrath)
						54216,
						19574,
					-- MAGE (Ice Block)
						45438,
					-- MONK
					-- PALADIN (Hand of Freedom / Hand of Protection / Divine Shield)
						1044,
						1022,
						642,
					-- PRIEST (Dispersion)
						47585,
					-- ROGUE
					-- SHAMAN (Windwalk Totem)
						114896,
					-- WARLOCK
					-- WARRIOR (Avatar / Bladestorm)
						107574,
						46924
				}
local immune			= {
						110700, --Divine Shield
						1022, --Hand of Protection
						45438, --Ice Block
						31224,--Cloak of Shadows
						19263, --Deterrence
						97417,--BrittleBarrier
						113506 -- Cyclone
}
local cc 			= { 
	108194,		-- Asphyxiate
	115001,		-- Remorseless Winter
	91800,		-- Gnaw
	91797,		-- Monstrous Blow (Dark Transformation)
	102795,		-- Bear Hug
	33786,		-- Cyclone
	99,			-- Disorienting Roar
	2637,		-- Hibernate
	22570,		-- Maim
	5211,		-- Mighty Bash
	9005,		-- Pounce
	110698,		-- Hammer of Justice 
	113004,		-- Intimidating Roar 
	113056,		-- Intimidating Roar 
	117526,		-- Binding Shot
	3355,		-- Freezing Trap
	1513,		-- Scare Beast
	19503,		-- Scatter Shot
	19386,		-- Wyvern Sting
	90337,		-- Bad Manner 
	24394,		-- Intimidation
	50519,		-- Sonic Blast 
	56626,		-- Sting 
	118271,		-- Combustion Impact
	44572,		-- Deep Freeze
	31661,		-- Dragon's Breath
	118,		-- Polymorph
	61305,		-- Polymorph: Black Cat
	28272,		-- Polymorph: Pig
	61721,		-- Polymorph: Rabbit
	61780,		-- Polymorph: Turkey
	28271,		-- Polymorph: Turtle
	82691,		-- Ring of Frost
	123393,		-- Breath of Fire 
	126451,		-- Clash
	122242,		-- Clash 
	119392,		-- Charging Ox Wave
	119381,		-- Leg Sweep
	115078,		-- Paralysis
	105421,		-- Blinding Light
	115752,		-- Blinding Light 
	105593,		-- Fist of Justice
	853,		-- Hammer of Justice
	119072,		-- Holy Wrath
	20066,		-- Repentance
	10326,		-- Turn Evil
	113506,		-- Cyclone 
	605,		-- Dominate Mind
	64044,		-- Psychic Horror
	8122,		-- Psychic Scream
	113792,		-- Psychic Terror 
	9484,		-- Shackle Undead
	87204,		-- Sin and Punishment
	2094,		-- Blind
	1833,		-- Cheap Shot
	1776,		-- Gouge
	408,		-- Kidney Shot
	113953,		-- Paralysis 
	6770,		-- Sap
	76780,		-- Bind Elemental
	77505,		-- Earthquake
	51514,		-- Hex
	118905,		-- Static Charge 
	118345,		-- Pulverize
	710,		-- Banish
	54786,		-- Demonic Leap
	5782,		-- Fear 
	118699,		-- Fear
	5484,		-- Howl of Terror
	6789,		-- Mortal Coil
	30283,		-- Shadowfury
	104045,		-- Sleep 
	89766,		-- Axe Toss 
	115268,		-- Mesmerize 
	6358,		-- Seduction 
	7922,		-- Charge Stun
	118895,		-- Dragon Roar
	5246,		-- Intimidating Shout 
	20511,		-- Intimidating Shout 
	132168,		-- Shockwave
	105771,		-- Warbringer
	107079,		-- Quaking Palm
	13327,		-- Reckless Charge
	20549		-- War Stomp
}
local roots				= {
						96294,	--Chains Of Ice
						91807,	--ShamblingRush
						339,		-- Entangling Roots
						19975,		-- Entangling Roots (Nature's Grasp)
						45334,		-- Immobilized (Wild Charge - Bear)
						102359,		-- Mass Entanglement
						110693,		-- Frost Nova (Mage)
						19185,		-- Entrapment
						128405,		-- Narrow Escape
						50245,		-- Pin (Crab)
						54706,		-- Venom Web Spray (Silithid)
						4167,		-- Web (Spider)
						122,		-- Frost Nova
						111340,		-- Ice Ward
						116706,		-- Disable
						113275,		-- Entangling Roots (Symbiosis)
						123407,		-- Spinning Fire Bloss
						113275,		-- Entangling Roots (Symbiosis)
						87194,		-- Glyph of Mind Blast
						114404,		-- Void Tendril's Grasp
						115197,		-- Partial Paralysis
						64695,		-- Earthgrab (Earthgrab Totem)
						63685,		-- Freeze (Frozen Power)
						107566,		-- Staggering Shout
						39965,		-- Frost Grenade
						55536,		-- Frostweave Net
						13099		-- Net-o-Matic
}

local disarm			= {
				-- DEATH KNIGHT (Pillar of Frost)
					51271,
				-- DRUID
		    	-- HUNTER (Bestial Wrath)
					19574,
				-- MAGE
				-- MONK
				-- PALADIN (Avenging Wrath)
					31884,
				-- PRIEST
				-- ROGUE (Shadow Dance / Adrenaline Rush)
					51713,
					13750,
				-- SHAMAN
					114049,
				-- WARLOCK
				-- WARRIOR (Recklessness / Avatar)
					1719,
					107574,
					 
}

local poiso = {
	
    2823,       --Deadly Poison
    8679       --Wound Poison

}

local poison = {
	
    3408,        --Crippling Poison
    5761,        --Mind-numbing Poison
    108215      --Paralytic Poison
}
-------------------------------------------------------------
function lpoison(unit)
for i=1,#poiso do
	if UnitBuffID(unit,poiso[i]) ~= nil
		then
			return true
		end
	end
end
--------------------------------------------------------------

function nlpoison(unit)
for i=1,#poison do
	if UnitBuffID(unit,poison[i]) ~= nil
		then
			return true
		end
	end
end

--------------------------------------------------------------

function hasCC(unit)
for i=1,#cc do
	if UnitDebuffID(unit,cc[i]) ~= nil
		then
			return true
		end
	end
end


-------------------------------------------------------------

function isSlowed(unit)
for i=1,#slows do
	if UnitDebuffID(unit,slows[i]) ~= nil
		then
			return true
		end
	end
end

-------------------------------------------------------------

function hasRoot(unit)
for i=1,#roots do
	if UnitDebuffID(unit,roots[i]) ~= nil
		then
			return true
		end
	end
end

-------------------------------------------------------------

function immuneToSlow(unit)
for i=1,#immuneToSlow do
	if UnitBuffID(unit,immuneToSlow[i]) ~= nil
		then
			return true
		end
	end
end

---------------------------------------------------------------
function isImmune(unit)
	for i=1,#immune do
		if UnitBuffID(unit,immune[i]) ~= nil
			then
				return true
			end
		end
end

--------------------------------------------------------------

function Disarm(unit)
	for i=1,#disarm do
		if UnitBuffID(unit,disarm[i]) ~= nil
			then 
				return true
			end	
		end
end


--------------------------------------------------

if SetFunctions == nil then

--------------------------------------------------

function HaveBuff(UnitID,SpellID,TimeLeft,Filter) 
  if not TimeLeft then TimeLeft = 0 end
  if type(SpellID) == "number" then SpellID = { SpellID } end 
  for i=1,#SpellID do 
    local spell, rank = GetSpellInfo(SpellID[i])
    if spell then
      local buff = select(7,UnitBuff(UnitID,spell,rank,Filter)) 
      if buff and ( buff == 0 or buff - GetTime() > TimeLeft ) then return true end
    end
  end
end

--------------------------------------------------

function HaveDebuff(UnitID,SpellID,TimeLeft,Filter) 
  if not TimeLeft then TimeLeft = 0 end
  if type(SpellID) == "number" then SpellID = { SpellID } end 
  for i=1,#SpellID do 
    local spell, rank = GetSpellInfo(SpellID[i])
    if spell then
      local debuff = select(7,UnitDebuff(UnitID,spell,rank,Filter)) 
      if debuff and ( debuff == 0 or debuff - GetTime() > TimeLeft ) then return true end
    end
  end
end

--------------------------------------------------

function CalculateHP(t)
  return 100 * ( UnitHealth(t)) / UnitHealthMax(t)
end

--------------------------------------------------

function CanHeal(t)
  if UnitCanCooperate("player",t) and not UnitIsEnemy("player",t) 
  and not UnitIsCharmed(t) and not UnitIsDeadOrGhost(t) and UnitAffectingCombat(t)
  and not HaveDebuff(t,{33786,122370}) 
  and not HaveBuff(t,{122370}) 
  then return true end 
end

--------------------------------------------------

function GroupInfo()
  members, group = { { Unit = "player", HP = CalculateHP("player") } }, { low = 0, tanks = { } } 
  group.type = IsInRaid() and "raid" or "party" 
  group.number = GetNumGroupMembers()
  for i=1,group.number do if CanHeal(group.type..i) then 
    local unit, hp = group.type..i, CalculateHP(group.type..i) 
    table.insert( members,{ Unit = unit, HP = hp } ) 
    if hp < 95 then group.low = group.low + 1 end 
    if UnitGroupRolesAssigned(unit) == "TANK" then table.insert(group.tanks,unit) end 
  end end 
  if group.type == "raid" and #members > 1 then table.remove(members,1) end 
  table.sort(members, function(x,y) return x.HP < y.HP end)
  local customtarget = CanHeal("target") and "target"  or CanHeal("mouseover") and GetMouseFocus() ~= WorldFrame and "mouseover" 
  if customtarget then table.sort(members, function(x) return UnitIsUnit(customtarget,x.Unit) end) end 
end


--------------------------------------------------




  SetFunctions = true

end


local function onUpdate(self,elapsed) 
  if self.time < GetTime() - 10 then
    if self:GetAlpha() == 0 then self:Hide() else self:SetAlpha(self:GetAlpha() - .05) end
  end
end

xrn = CreateFrame("Frame",nil,ChatFrame1) 
xrn:SetSize(ChatFrame1:GetWidth(),30)
xrn:Hide()
xrn:SetScript("OnUpdate",onUpdate)
xrn:SetPoint("TOP",0,0)
xrn.text = xrn:CreateFontString(nil,"OVERLAY","MovieSubtitleFont")
xrn.text:SetAllPoints()
xrn.texture = xrn:CreateTexture()
xrn.texture:SetAllPoints()
xrn.texture:SetTexture(0,0,0,.50) 
xrn.time = 0

function xrn:message(message) 
  self.text:SetText(message)
  self:SetAlpha(1)
  self.time = GetTime() 
  self:Show() 
end

local colors = RAID_CLASS_COLORS[select(2,UnitClass("player"))] 
xrn:message("Lolomo PVP "..string.format("|cff%02x%02x%02x", colors.r*255, colors.g*255, colors.b*255).." ")